]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
search: Allow grid using search providers to specify maximum of results
authorSebastian Keller <skeller@gnome.org>
Wed, 1 Nov 2023 17:15:22 +0000 (18:15 +0100)
committerMarge Bot <marge-bot@gnome.org>
Fri, 3 Nov 2023 20:39:28 +0000 (20:39 +0000)
When GridSearchResults::_getMaxDisplayedResults() is called after the
first character has been entered in the search, GridSearchResults has
no children yet. _getMaxDisplayedResults() tries to determine the
maximum number of search results based on how often the largest child
would fit into the allocated size or -1 (i.e. no limit) if there are no
children. So for the initial search there is no limit and in the app
search all matching apps get added as possible results, which due to the
search term being only a single character is almost all installed apps.
This now causes allocation to be run for all these results, despite the
vast majority of them never being visible, which on slower machines can
cause noticeable delays before the search results are displayed.

This now adds the ability for search providers to specify a maximum
number of results that gets used instead of -1 when specified. By being
provider specific this means extensions implementing their own providers
will not be affected by this.

Further this sets the maximum for the app search provider to 6 as per
the current designs.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7155
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3004>

js/ui/appDisplay.js
js/ui/search.js

index dc21331185f2ed606afaf69da1c33d3ac16f6360..1ecdb23c3094c5450e9a68b0125ea5c7eb4cba85 100644 (file)
@@ -1798,6 +1798,7 @@ export class AppSearchProvider {
         this.id = 'applications';
         this.isRemoteProvider = false;
         this.canLaunchSearch = false;
+        this.maxResults = 6;
 
         this._systemActions = new SystemActions.getDefault();
 
index b938b0327b2cb5bc01ddf8260131ede084173ef3..071f6332b1c7437e795029941c43a8a60ef7d2ad 100644 (file)
@@ -472,6 +472,8 @@ class GridSearchResults extends SearchResultsBase {
             child: this._grid,
             x_align: Clutter.ActorAlign.CENTER,
         }));
+
+        this._maxResults = provider.maxResults ?? -1;
     }
 
     _onDestroy() {
@@ -510,11 +512,18 @@ class GridSearchResults extends SearchResultsBase {
     }
 
     _getMaxDisplayedResults() {
-        let width = this.allocation.get_width();
+        const width = this.allocation.get_width();
         if (width === 0)
-            return -1;
+            return this._maxResults;
+
+        const nCols = this._grid.layout_manager.columnsForWidth(width);
+        if (nCols < 0)
+            return this._maxResults;
+
+        if (this._maxResults < 0)
+            return nCols;
 
-        return this._grid.layout_manager.columnsForWidth(width);
+        return Math.min(nCols, this._maxResults);
     }
 
     _clearResultDisplay() {